#include<iostream>
#include<functional>
#include<errno.h>
#include<string.h>
#include"Socket.hpp"
#include"EventLoop_Timequeue.hpp"
#include"Connection.hpp"
#include"Acceptor.hpp"
#include"LoopThread.hpp"
#include"Server.hpp"

void MsgCallback(const ConnPtr &conn,Buffer *buf)
{
    char buftmp[1024];
    buf->ReadAndMove(buftmp,buf->ReadableSize());
    LOG_DBG("recv msg :%s",buftmp);
    std::string str = "hello world";
    conn->Send(str.c_str(),str.size());//发送消息
}
void ConnectCallback(const ConnPtr &conn)
{
    LOG_INF("new connection %p",conn.get());
}
void CloseCallback(const ConnPtr &conn)
{
    LOG_INF("connection %p closed",conn.get());
}


int main()
{
    TcpServer server(8888);
    server.SetMessageCallback(MsgCallback);
    server.SetConnectedCallback(ConnectCallback);
    server.SetClosedCallback(CloseCallback);
    server.EnableInactiveConnectionClose(5);//设置超时时间
    server.SetThreadNum(8);//设置线程数
    server.Start();

    return 0;
}


